package com.itheima.tcp;

import java.io.*;
import java.net.Socket;

public class SocketDemoFour01 {
    public static void main(String[] args) throws IOException {
        //TCP客户端四次握手
        //1.创建一个socket对象
        Socket socket = new Socket("127.0.0.1", 8080);
        //2.获取一个io流写数据
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("ddd".getBytes());
        socket.shutdownOutput();//仅仅关闭输出流，并写一个结束标记，不会对socket有任何影响
        //3.释放
//        InputStream inputStream = socket.getInputStream();
//        int b;
//        while ((b = inputStream.read()) != -1) {
//            System.out.println((char) b);
//        }
//        inputStream.close();
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String len;
        while ((len = br.readLine()) != null) {
            System.out.println(len);
        }
        br.close();
        socket.close();
        outputStream.close();
    }
}
